-
Notifications
You must be signed in to change notification settings - Fork 32
🎨 Reduce the number of acquisition/release of DB connection inside function repository #7904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🎨 Reduce the number of acquisition/release of DB connection inside function repository #7904
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the functions repository to consolidate connection handling, improve transactional usage, and leverage Pydantic’s new from_attributes support for model validation.
- Wraps all repository operations in
pass_or_acquire_connectionto reuse or acquire DB connections. - Updates
transaction_contextusage to work with the returnedtransactionobject for both streams and executes. - Removes manual
dict(row)conversions by enabling Pydantic’smodel_config = ConfigDict(from_attributes=True).
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| services/web/server/src/simcore_service_webserver/functions/_functions_repository.py | Added pass_or_acquire_connection, adjusted transactions to use transaction, and simplified model_validate calls. |
| packages/models-library/src/models_library/functions.py | Enabled Pydantic’s from_attributes parsing for DB row objects by adding model_config. |
Comments suppressed due to low confidence (2)
services/web/server/src/simcore_service_webserver/functions/_functions_repository.py:696
- [nitpick] The call to
check_user_permissionsuses a positionalconnargument, whereas other calls explicitly nameconnection=conn. For consistency and clarity, consider using the named parameterconnection=conn.
await check_user_permissions(
services/web/server/src/simcore_service_webserver/functions/_functions_repository.py:125
- [nitpick]
get_asyncpg_engine(app)is being called repeatedly in each function. Consider fetching the engine once (e.g.,engine = get_asyncpg_engine(app)) at the start of the repository module or function to reduce overhead.
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7904 +/- ##
==========================================
+ Coverage 87.97% 89.68% +1.70%
==========================================
Files 1845 1454 -391
Lines 71153 60138 -11015
Branches 1220 476 -744
==========================================
- Hits 62594 53932 -8662
+ Misses 8207 6085 -2122
+ Partials 352 121 -231
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
@mergify queue |
🟠 Waiting for conditions to match
|
wvangeit
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sanderegg
matusdrobuliak66
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
bisgaard-itis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Thanks a lot for the quick fix 👍🏻
c06a353 to
b7c90c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 thanks, looks good
|
@sanderegg I believe this PR also closes Can I get you to set this in your PR description? (I didn't do it myself in case you disagree) |
pcrespov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx
wvangeit
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a look again. Looks good to me as far as I can see.
0059151 to
f0db78d
Compare
043d7dd to
ceb430f
Compare
|
@mergify queue |
✅ The pull request has been merged automaticallyThe pull request has been merged automatically at eccf0c0 |
|


What do these changes do?
As spotted with @bisgaard-itis we discovered that running under load some functions would timeout while trying to acquire a DB connection. This should improve that situation.
Related issue/s
How to test
Dev-ops